const user = {
  namespaced: true,
  state: {
    msg: "hello world",
    count: 0,
    list: [1, 2, 3, 4, 5, 6, 7, 8, 9],
  },
  getters: {
    // getters相当于vue中的computed计算属性
    // 传参
    calculatedCount(state) {
      return state.count * 10;
    },
    filtrateArr(state) {
      state.list.push(state.count);
      return state.list.filter((item) => item > 5);
    },
  },
  mutations: {
    // mutations相当于vue中的methods方法
    addNum(state, payload) {
      state.count += payload;
    },
    // 弹窗
    viewModel(state, payload) {
      alert((state.count += payload));
    },
    // 双向绑定
    twoWayBinding(state, payload) {
      state.msg = payload;
    },
  },
  actions: {
    // actions相当于vue中的methods方法
    requestData({ commit }, payload) {
      setTimeout(() => {
        commit("addNum", payload);
      });
    },
  },
};

export default user;
